package com.monkey.model.comparator;

import com.monkey.model.monkey.MonkeyTradeData;

import java.util.Comparator;

/**
 * desc:
 * auth: chenxiaobin
 * data: 2018/1/14.
 */
public class MonkeyTradeReproductComparator implements Comparator<MonkeyTradeData> {
    private boolean order;

    public MonkeyTradeReproductComparator(boolean order) {
        this.order = order;
    }

    @Override
    public int compare(MonkeyTradeData object1, MonkeyTradeData object2) {
        Integer g1 = object1.getGeneration();
        Integer g2 = object2.getGeneration();
        Float p1 = object1.getPrice();
        Float p2 = object2.getPrice();
        Float w1 = object1.getWeight();
        Float w2 = object2.getWeight();
        Integer r1 = object1.getRepoductCount();
        Integer r2 = object2.getRepoductCount();

        if (order) {
            if (r1.equals(r2)) {
                if (p1.equals(p2)) {
                    if (g1.equals(g2)) {
                        return w1.compareTo(w2);
                    } else if (g1 < g2) {
                        return -1;
                    } else {
                        return 1;
                    }
                } else if (p1 < p2) {
                    return -1;
                } else {
                    return 1;
                }
            } else if (r1 < r2) {
                return -1;
            } else {
                return 1;
            }
        } else {
            if (r2.equals(r1)) {
                if (p2.equals(p1)) {
                    if (g2.equals(g1)) {
                        return w2.compareTo(w1);
                    } else if (g2 < g1) {
                        return -1;
                    } else {
                        return 1;
                    }
                } else if (p2 < p1) {
                    return -1;
                } else {
                    return 1;
                }
            } else if (r2 < r1) {
                return -1;
            } else {
                return 1;
            }
        }
    }
}
